package com.yzt.message.util;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

import io.rong.imkit.conversationlist.model.BaseUiConversation;

/**
 * 私聊会话管理器
 */
public class ConversationMessageManager {

    private static ConversationMessageManager mInstance;

    //用户发送的消息列表，过滤系统消息
    private List<BaseUiConversation> conversationList = new ArrayList<>();

    private final CopyOnWriteArrayList<String> unReplyUidList = new CopyOnWriteArrayList<>();

    private ConversationMessageManager() {

    }

    public static ConversationMessageManager getInstance() {
        if (mInstance == null) {
            synchronized (ConversationMessageManager.class) {
                if (mInstance == null) {
                    mInstance = new ConversationMessageManager();
                }
            }
        }
        return mInstance;
    }

    public void initConversation(List<BaseUiConversation> conversations) {
        conversationList.clear();
        if (conversations == null || conversations.isEmpty()) {
            return;
        }
        conversationList.addAll(conversations);
    }

    public List<BaseUiConversation> getConversationList() {
        return conversationList;
    }

    public void setConversationList(List<BaseUiConversation> conversationList) {
        if (conversationList == null || conversationList.isEmpty()) {
            return;
        }
        this.conversationList.clear();
        this.conversationList = conversationList;
    }

    public int getConversationSize() {
        return this.conversationList.size();
    }

    public BaseUiConversation getFirstConversation() {
        return this.conversationList.get(0);
    }

    public List<String> getUnReplyList() {
        return unReplyUidList;
    }

    public void setUnReplyList(List<String> unReplyList) {
        if (unReplyList == null || unReplyList.isEmpty()) {
            return;
        }
        this.unReplyUidList.clear();
        this.unReplyUidList.addAll(unReplyList);
    }

    public void cleanUnReplyList() {
        this.unReplyUidList.clear();
    }

    public boolean unReplyContains(String obj) {

        return UserInfoManager.getInstance().isIntimacy(obj);
    }

    public void addUnReplyUid(String uid) {
        this.unReplyUidList.add(uid);
    }

}
